import { defineStore } from 'pinia'
import { cartList } from '@/api/cart'

const useCartInfo = defineStore('cart', {
    state: () => {
        return {
            count: 0, //购物车 有多少种商品
            list: [] //购物车信息列表
        }
    },
    actions: {
        // 调用接口获取 购物车信息
        async getCartInfo() {
            let res = await cartList({
                page: 1,
                limit: 100
            })

            this.list = res.data.list && res.data.list.filter((item) => { return item.goods_info }) || []
            this.count = this.list.length
        }
    }
})

export default useCartInfo